<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-18 22:33:04
 * @LastEditTime: 2023-09-23 12:23:59
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Models;

class Subject extends BaseModel
    {
    //
    public $table = "basedata_finance_subject";
    protected $guarded = [];
    public function childrentree()
        {
        return $this->hasMany(get_class($this), 'parent_id', 'id')->with(['status', 'direct', 'parent', 'trade']);
        }
    public function children()
        {
        return $this->childrentree()->with(["children"]);
        }
    public function parent()
        {
        return $this->belongsTo(get_class($this), 'parent_id', 'id');
        }
    public function direct()
        {
        return $this->belongsTo(Dic::class, "direct_id", "key")->where(function ($q)
            {
            $q->where("dic_category_id", 31);
            $q->where("code", 'FinanceDirect');

            });
        }
    public function status()
        {
        return $this->belongsTo(Dic::class, "status_id", "key")->where(function ($q)
            {
            $q->where("code", 'table_status');
            });
        }
    public function trade()
        {
        return $this->belongsTo(Trade::class);
        }

    }